#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 10010;

struct Student {
	int id;
	int score[6];
	bool flag;  // 是否能有通过编译的提交
	int total_score;
	int solve;  // 完美解题数
}stu[maxn];

bool cmp(Student a, Student b) {
	if (a.total_score != b.total_score) return a.total_score > b.total_score;
	else if (a.solve != b.solve) return a.solve > b.solve;
	else return a.id < b.id;
}

int main() {
	int n, k, m;
	int full[6];
	int user_id, problem_id, score_get;

	scanf("%d%d%d", &n, &k, &m);
	for (int i = 1; i <= n; i++) {
		stu[i].id = i;
		stu[i].total_score = 0;
		stu[i].solve = 0;
		stu[i].flag = false;
		memset(stu[i].score, -1, sizeof(stu[i].score));  // 初始化所有得分为 -1
	}
	for (int i = 1; i <= k; i++) {
		scanf("%d", &full[i]);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &user_id, &problem_id, &score_get);
		if (score_get != -1) {
			stu[user_id].flag = true;
		}
		if (score_get == -1 && stu[user_id].score[problem_id] == -1) {
			stu[user_id].score[problem_id] = 0;
		}
		if (score_get == full[problem_id] && stu[user_id].score[problem_id] < full[problem_id]) {
			stu[user_id].solve++;
		}
		if (score_get > stu[user_id].score[problem_id]) {
			stu[user_id].score[problem_id] = score_get;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			if (stu[i].score[j] != -1) {
				stu[i].total_score += stu[i].score[j];
			}
		}
	}

	sort(stu+1, stu+n+1, cmp);
	int r = 1;
	for (int i = 1; i <= n && stu[i].flag == true; i++) {
		if (i != 1 && stu[i].total_score != stu[i-1].total_score) {
			r = i;
		}
		printf("%d %05d %d", r, stu[i].id, stu[i].total_score);
		for (int j = 1; j <= k; j++) {
			if (stu[i].score[j] == -1) {
				printf(" -");
			} else {
				printf(" %d", stu[i].score[j]);
			}
		}
		printf("\n");
	}

	return 0;
}
